/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tnviet.proj.jna.utilities;

import java.text.DecimalFormat;

/**
 *
 * @author Administrator
 */
public class TrafficRendererUtils {

    public static String renderTraffic(double traffic){
        String post = "";
        String ret = "";
        DecimalFormat format = new DecimalFormat("0.0");
        if(traffic/8 > Math.pow(2, 20)){
            post = "GB";
            ret = format.format(traffic/(8*Math.pow(2, 20)));
            return ret + " " + post;
        } else if (traffic/8 > Math.pow(2, 10)){
            post = "MB";
            ret = format.format(traffic/(8*Math.pow(2, 10)));
            return ret + " " + post;
        } else {
            post = "KB";
            ret = format.format(traffic/(8));
            return ret + " " + post;
        }
    }
    public static void main(String[] args){
        System.out.println(renderTraffic(250000.34));
    }

}
